package com.xgz.controller;

import com.xgz.entity.LayData;
import com.xgz.entity.LayTreeData;
import com.xgz.entity.TMenu;
import com.xgz.service.TMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (TMenu)表控制层
 *
 * @author makejava
 * @since 2022-10-25 14:48:32
 */
@Controller
@RequestMapping("tMenu")
public class TMenuController {
    /**
     * 服务对象
     */
    @Autowired
    private TMenuService tMenuService;

    // 查询所有的菜单 并且对应好他们之间的父子关系
    @GetMapping("queryMenus")
    public String queryAll(HttpServletRequest request){
        List<TMenu> tMenus = tMenuService.queryAll();
        System.out.println("000000000000000000000000000000");
        System.out.println("controller  tMenus = " + tMenus.toString());
        request.setAttribute("menus",tMenus);
        return "index";
    }

    // 查询除tree所需要的数据   只要ajax LayData
    @GetMapping("treedata")
    @ResponseBody
    public LayData getAllMenu(){
        List<LayTreeData> treeDataList = tMenuService.queryAllTreeData();
        System.out.println("treeDataList = " + treeDataList);

        return new LayData(treeDataList);
    }

    @GetMapping("checkData/{rid}")
    @ResponseBody
    public LayData checkData(@PathVariable Integer rid){
        List<Integer> checkDataList = tMenuService.getcheckDataList(rid);
        return new LayData(checkDataList);
    }

}

